package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.iview.IDeleteProductWorkPartView;
import com.cloudsigns.factorymanager2.produce.model.DeleteProductWorkPartModel;
import com.cloudsigns.factorymanager2.produce.model.IDeleteProductWorkPartModel;

public class DeleteProductWorkPartPresenter {
    private IDeleteProductWorkPartView view;
    private IDeleteProductWorkPartModel model;
    private Handler handler = new Handler();

    public DeleteProductWorkPartPresenter(IDeleteProductWorkPartView view) {
        this.view = view;
        this.model = new DeleteProductWorkPartModel();
    }

    public void deleteProductWorkPart() {
        model.deleteProductWorkPart(view.getName(), new DeleteProductWorkPartModel.OnDeleteProductWorkPartListener() {
            @Override
            public void successed() {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.deleteProductWorkPartSuccessed();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.deleteProductWorkPartFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
